package lumis.portal.webfilereplication;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import lumis.portal.event.persistence.PortalEventEntityListener;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.GenericGenerator;

/**
 * Type of a web file replication.
 * 
 * @version $Revision: 13093 $ $Date: 2011-05-28 18:40:18 -0300 (Sat, 28 May 2011) $
 * @since 6.0.0
 */
@SuppressWarnings("serial")
@Entity
@Table(name = "lum_WFRType")
@GenericGenerator(name = "portal-guid", strategy = "lumis.portal.dao.hibernate.GuidGenerator")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@EntityListeners(value = PortalEventEntityListener.class)
public class WebFileReplicationType implements Serializable
{
	@Id
	@GeneratedValue(generator = "portal-guid")
	private String id;

	private String name;

	private String fileReplicatorClassName;

	@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
	@OneToMany(mappedBy = "type", cascade = CascadeType.ALL)
	@OrderBy("name")
	private Collection<WebFileReplicationProperty> properties = new ArrayList<WebFileReplicationProperty>();

	/**
	 * Returns the identifier of the type.
	 * 
	 * @return the identifier of the type.
	 * @since 6.0.0
	 */
	public String getId()
	{
		return id;
	}

	/**
	 * Returns the name of the type.
	 * 
	 * @return the name of the type.
	 * @since 6.0.0
	 */
	public String getName()
	{
		return name;
	}

	/**
	 * Defines the name of the type.
	 * 
	 * @param name
	 *            the name to be defined.
	 * @since 6.0.0
	 */
	void setName(String name)
	{
		this.name = name;
	}

	/**
	 * Returns the file replicator class name of the type.
	 * 
	 * @return the file replicator class name of the type.
	 * @since 6.0.0
	 */
	String getFileReplicatorClassName()
	{
		return fileReplicatorClassName;
	}

	/**
	 * Defines the file replicator class name of the type.
	 * 
	 * @param fileReplicatorClassName
	 *            the file replicator class name to be defined.
	 * @since 6.0.0
	 */
	void setFileReplicatorClassName(String fileReplicatorClassName)
	{
		this.fileReplicatorClassName = fileReplicatorClassName;
	}

	/**
	 * Returns the custom properties of the type.
	 * 
	 * @return the custom properties of the type.
	 * @since 6.0.0
	 */
	public Collection<WebFileReplicationProperty> getProperties()
	{
		return properties;
	}
}
